
package com.tenentia.pcmps.swm.web.jsf.tables.implementation;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.tenentia.pcmps.swm.business.BusinessLogicObjectsFactory;
import com.tenentia.pcmps.swm.business.interfaces.PDFTemplatesManager;
import com.tenentia.pcmps.swm.data.beans.PDFTemplate;
import com.tenentia.pcmps.swm.web.jsf.tables.JSFTableDataProvider;

/**
 * 
 * @author tEnEntia, S.L.N.E.
 * 
 */
public class PDFTemplatesTableDataProvider implements JSFTableDataProvider {

	private static final Logger LOGGER = Logger.getLogger(PDFTemplatesTableDataProvider.class.getPackage().getName());

	public PDFTemplatesTableDataProvider() {

		super();
	}

	@Override
	public List<Object> getItemsByRange(Integer firstRow, Integer numberOfRows, Object filterParameters, Object sortParameters) {

		List<Object> methodResult = new ArrayList<Object>();

		try {
			PDFTemplatesManager businessLogicObject = (PDFTemplatesManager) BusinessLogicObjectsFactory.getInstance().createNewBusinessObject(BusinessLogicObjectsFactory.PDF_TEMPLATES_MANAGER);
			List<PDFTemplate> tmpList = businessLogicObject.getTableItemsByRange(filterParameters, sortParameters, firstRow, numberOfRows);
			for (int i = 0; i < tmpList.size(); i++) {
				methodResult.add(tmpList.get(i));
			}
		} catch (Exception e) {
			LOGGER.error(e, e);
		}

		return methodResult;
	}

	@Override
	public Integer getRowCount(Object filterParameters) {

		Integer methodResult = Integer.valueOf(0);

		try {
			PDFTemplatesManager businessLogicObject = (PDFTemplatesManager) BusinessLogicObjectsFactory.getInstance().createNewBusinessObject(BusinessLogicObjectsFactory.PDF_TEMPLATES_MANAGER);
			methodResult = businessLogicObject.getTableRowCount(filterParameters);
		} catch (Exception e) {
			LOGGER.error(e, e);
		}

		return methodResult;
	}

}
